import React, { Component } from 'react'

export default class MyTextContent extends Component {

    state = {
        isOpen: false
    }

    render() {
        const { text, length } = this.props
        const { isOpen } = this.state
        return (
            <div>
                {
                    text.length <= length ? 
                    <span>{text}</span> 
                    :
                    isOpen ? 
                    <span>{text}</span> 
                    : 
                    <span>{text.substring(0,length)}<a 
                    style = {{fontSize:'10px'}}
                    href="javascript:;"
                    onClick = {()=>{
                        this.setState({isOpen : true})
                    }}>&emsp;更多</a></span>
                }
            </div>
        )
    }
}